package animalsound;

public class animalsound {
	public static abstract class Animal {
	    public abstract void cry();
	    public abstract String getAnimalName();
	}
	
	public static class Simulator {
	    public void playSound(Animal animal) {
	        System.out.println(animal.getAnimalName() + "的声音：");
	        animal.cry();
	    }
	}
	
	public static class Dog extends Animal { 
	    public void cry() {
	        System.out.println("汪~汪~汪~");
	    }
	    public String getAnimalName() {
	        return "狗";
	    }
	}

	public static class Cat extends Animal { 
	    public void cry() {
	        System.out.println("喵~喵~喵~");
	    }
	    public String getAnimalName() {
	        return "猫";
	    }
	}
	
	public static class Application {
	    public static void main(String[] args) {
	        Simulator simulator = new Simulator();
	        simulator.playSound(new Dog());
	        simulator.playSound(new Cat());
	    }
	}
	
}
